package com.itboye.mengwu.collection;

import java.util.Observable;
import java.util.Observer;

import android.R.color;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.ui.mymeng.CounTxtFragment;
import com.itboye.mengwu.app.ui.roof.ActivityHomePageSearch;
import com.itboye.mengwu.app.ui.roof.HomePageItemFragmentTypeTwo;
import com.itboye.mengwu.app.ui.roof.TodaySpecialOfferItemFragment;
import com.itboye.mengwu.data.model.IndexModel;
import com.itboye.mengwu.data.model.LunBoModel;
import com.itboye.mengwu.data.presenter.AddGoodsPresenter;
import com.itboye.mengwu.data.presenter.LunBoPresenter;
import com.itboye.mengwu.widget.PagerSlidingTabStrip;

/***
 * 屋顶Fragment
 * 
 * @author dsawe
 * 
 */
public class CollectionFragment extends BaseActivity {
	String[] titles = { "商品收藏", "内容收藏" };
	ViewPager pager;
	PagerSlidingTabStrip tabs;
	private ImageView back;
	LunBoPresenter boPresenter;

	private AddGoodsPresenter detailPresenter;

	CollectionConentItemFragment collectionConentItemFragment = new CollectionConentItemFragment();
	CounTxtFragment counTxtFragment = new CounTxtFragment();
	TextView goodCollect, contentCollect, edit;
	View goodCollectLine, contentCollectLine;
	boolean flag = true;
	RelativeLayout goodCollectLayout;
	RelativeLayout contentCollectLayout;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_collection;
	}

	@Override
	public void onMyCreate() {

		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		// pager.setAdapter(new MyAdapter(getSupportFragmentManager(), titles));
		// tabs.setViewPager(pager);
		//
		// = (RelativeLayout) findViewById(R.id.goodCollectLayout);
		// = (RelativeLayout) findViewById(R.id.contentCollectLayout);

		// goodCollect = (TextView) findViewById(R.id.goodCollect);
		// goodCollectLine = findViewById(R.id.goodCollectLine);
		//
		// contentCollect = (TextView) findViewById(R.id.contentCollect);
		// contentCollectLine = findViewById(R.id.contentCollectLine);

		goodCollectLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				goodCollectLine.setVisibility(View.VISIBLE);
				contentCollectLine.setVisibility(View.GONE);

				FragmentManager fm = getSupportFragmentManager();
				// 开启Fragment事务
				FragmentTransaction transaction = fm.beginTransaction();

				if (collectionConentItemFragment == null) {
					collectionConentItemFragment = new CollectionConentItemFragment();
				}
				// 使用当前Fragment的布局替代id_content的控件
				transaction.replace(R.id.frameLayout,
						collectionConentItemFragment);

				transaction.commit();

				edit.setVisibility(View.VISIBLE);

			}
		});
		contentCollectLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				goodCollectLine.setVisibility(View.GONE);
				contentCollectLine.setVisibility(View.VISIBLE);

				// TODO Auto-generated method stub
				FragmentManager fm = getSupportFragmentManager();
				// 开启Fragment事务
				FragmentTransaction transaction = fm.beginTransaction();

				if (counTxtFragment == null) {
					counTxtFragment = new CounTxtFragment();
				}
				// 使用当前Fragment的布局替代id_content的控件
				transaction.replace(R.id.frameLayout, counTxtFragment);

				transaction.commit();

				edit.setVisibility(View.GONE);
				flag = true;
			}
		});
		// 设置默认的Fragment
		setDefaultFragment();

		edit.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				CollectionConentItemFragment collectionConentItemFragment = new CollectionConentItemFragment();
				Bundle bundle = new Bundle();
				bundle.putBoolean("flag", flag);
				collectionConentItemFragment.setArguments(bundle);
				flag = !flag;

				FragmentManager fm = getSupportFragmentManager();
				// 开启Fragment事务
				FragmentTransaction transaction = fm.beginTransaction();

				// if (collectionConentItemFragment == null) {
				// collectionConentItemFragment = new
				// CollectionConentItemFragment();
				// }
				// 使用当前Fragment的布局替代id_content的控件
				transaction.replace(R.id.frameLayout,
						collectionConentItemFragment);

				transaction.commit();
			}
		});

	}

	private void setDefaultFragment() {
		// TODO Auto-generated method stub
		FragmentManager fm = getSupportFragmentManager();
		FragmentTransaction transaction = fm.beginTransaction();
		collectionConentItemFragment = new CollectionConentItemFragment();
		transaction.replace(R.id.frameLayout, collectionConentItemFragment);
		transaction.commit();
	}

	// public class MyAdapter extends FragmentStatePagerAdapter {
	// String[] _titles;
	//
	// public MyAdapter(FragmentManager fm, String[] titles) {
	// super(fm);
	// _titles = titles;
	// }
	//
	// @Override
	// public CharSequence getPageTitle(int position) {
	// return _titles[position];
	// }
	//
	// @Override
	// public int getCount() {
	// return _titles.length;
	// }
	//
	// @Override
	// public Fragment getItem(int position) {
	// Fragment bfrag2 = null;
	// if (position == 0) {
	// bfrag2 = new CollectionConentItemFragment();
	// } else {
	// bfrag2 = new CounTxtFragment();
	// }
	// return bfrag2;
	// }
	//
	// }

}
